<template>
  <view class="container">
    <view class="form-group">
      <text>收货人姓名：</text>
      <input v-model="address.name" type="text" placeholder="请输入姓名">
    </view>
    <view class="form-group">
      <text>电话号码：</text>
      <input v-model="address.phone" type="text" placeholder="请输入电话">
    </view>
    <view class="form-group">
      <text>省市区：</text>
      <input v-model="address.province" type="text" placeholder="省份">
      <input v-model="address.city" type="text" placeholder="城市">
      <input v-model="address.town" type="text" placeholder="区县">
    </view>
    <view class="form-group">
      <text>详细地址：</text>
      <input v-model="address.address" type="text" placeholder="请输入详细地址">
    </view>
    <button @click="admitAddress" type="sucess">提交</button>
	<button @click="cancelAddress" type="">取消</button>
  </view>
</template>


<script>
	 import config from '@/config'; // 根据实际情况引入 config

	export default {
		data() {
			return {
				  address: {
				          name: '',
				          phone: '',
				          province: '',
				          city: '',
				          town: '',
				          address: ''
				        }

			}
		},
		methods: {
			admitAddress(){
				console.log("提交按钮被点击")
				uni.request({
				  url: `${config.apiUrl}/address/add`,
				  method: 'POST',
				  data: this.address,
				  success: (response) => {
				    // 处理成功响应
				    console.log('Address saved successfully:', response.data);
				  },
				  fail: (error) => {
				    // 处理错误响应
				    console.error('Error saving address:', error);
				  }
				});
				uni.reLaunch({
					url:'/pages/mine/address/index'
				})
			},
			cancelAddress(){
				uni.reLaunch({
					url:'/pages/mine/address/index'
				})
			}
		}
	}
</script>

<style>
  .container {
  padding: 20px;
  background-color: #ffefba;
   
  height: 550px;
  }
  .form-group {
    display: flex;
    flex-direction: row;
    align-items: center;
    margin-bottom: 40px; /* 增加每个输入组之间的间距 */
  }
  .form-group text {
    margin-right: 10px;
  }
  .input-container {
    background-color: #f0f0f0; /* 浅灰色背景 */
    border-radius: 10px; /* 圆角 */
    padding: 10px; /* 内边距 */
  }
  .form-group input {
    flex: 1;
    margin-right: 10px;
  }

</style>
